package com.umeox.watch.moto.dataservice.db.model;

import androidx.annotation.NonNull;
import androidx.room.Entity;
import androidx.room.Ignore;
import androidx.room.PrimaryKey;

import com.umeox.moto.common.utils.AndroidUtils;
import com.umeox.watch.moto.apiclient.model.DeviceCodeDTO;

/**
 * Created by Rambo 2021/9/16
 * Describe:
 */
@Entity(tableName = DeviceCode.TABLE_NAME)
public class DeviceCode {

    @Ignore
    public static final String TABLE_NAME = "device_code";


    @NonNull
    @PrimaryKey
    private String deviceId;

    /**
     * 二维码
     */
    private String qrCode;
    /**
     * 设备动态绑定码
     */
    private String bindCode;
    /**
     * 过期时间，unix时间戳，精度到毫秒
     */
    private long expiredTime;

    public static DeviceCode covertDeviceCode(DeviceCodeDTO deviceCodeDTO) {
        DeviceCode deviceCode= new DeviceCode();
        deviceCode.setDeviceId(AndroidUtils.getDeviceId());
        deviceCode.setQrCode(deviceCodeDTO.qrCode);
        deviceCode.setBindCode(deviceCodeDTO.bindCode);
        deviceCode.setExpiredTime(deviceCodeDTO.expiredTime);
        return deviceCode;
    }

    public String getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }

    public String getQrCode() {
        return qrCode;
    }

    public void setQrCode(String qrCode) {
        this.qrCode = qrCode;
    }

    public String getBindCode() {
        return bindCode;
    }

    public void setBindCode(String bindCode) {
        this.bindCode = bindCode;
    }

    public long getExpiredTime() {
        return expiredTime;
    }

    public void setExpiredTime(long expiredTime) {
        this.expiredTime = expiredTime;
    }

    @Override
    public String toString() {
        return "DeviceCode{" +
                "deviceId='" + deviceId + '\'' +
                ", qrCode='" + qrCode + '\'' +
                ", bindCode='" + bindCode + '\'' +
                ", expiredTime=" + expiredTime +
                '}';
    }
}
